package cn.wolfcode.web.controller;
import cn.wolfcode.domain.MessageBoard;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IMessageBoardService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/messageBoard")
public class MessageBoardController {

    @Autowired
    private IMessageBoardService messageBoardService;

    //处理查询所有留言消息的请求 /message/list
    @RequestMapping("/list")
    public String list(Model model, QueryObject qo){
       /* List<MessageBoard> messageBoard=messageBoardService.listAll();
        model.addAttribute("messageBoard",messageBoard);*/


        PageInfo<MessageBoard> pageInfo = messageBoardService.query(qo);//查出数据
        model.addAttribute("pageInfo",pageInfo);
        //model拿到数据后与jsp合并渲染成HTML格式，展现在页面上
        return "message/list";  // /WEB-INF/views/messageBoard/list.ftl
    }

    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(MessageBoard messageBoard){
        messageBoard.setCreateTime(new Date());
        messageBoard.setReplystatus(false);
        messageBoardService.save(messageBoard);
        return "redirect:/messageBoard/list";  //localhost/messageBoard/list
    }

}
